home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 21.6 KB | 519 lines | [TEXT/CCL2] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;marking-menu-demo.lisp
- ;;
- ;; Copyright © 1992 University of Toronto, Department of Computer Science
- ;; All Rights Reserved
- ;;
- ;; author: Mark A. Tapia
- ;;
- ;; A demonstration of marking menus
- ;;
- ;; To use this demonstration, first load "init-menus.lisp"
- ;; and then evaluate the form:
- ;; (menus::load-marking-demo)
- ;; Finally evalute the form:
- ;; (marking-demo)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package cl-user)
- (eval-when (eval compile)
- (require 'oou-utils)
- (require 'marking-menus)
- (require 'check-menus))
- (use-package 'menus)
- (import '(menus::queued-modal-dialog menus::containing-view))
-
- (defvar *floating* t "Floating menus?")
- (defvar *opaque* nil "Opaque menus?")
- (defvar *custom* nil)
- (defparameter default-font '("Times" 14 :srcor :plain))
- (defvar *testing* nil)
-
-
- (defmacro stack-toplevel (new-level &rest body)
- `(let ((old-level (%set-toplevel)))
- (unwind-protect
- (progn
- (%set-toplevel ,new-level)
- ,@body)
- (%set-toplevel old-level))))
-
- (defmethod get-menu-options ((view marking-menu-view))
- ;; set the menu defaults for the marking-menu-view
- (setf (slot-value view 'menus::menu-floating) *floating*
- (slot-value view 'menus::menu-opaque) *opaque*))
-
- ;; nested-window
- ;; a specialized version of a marking-menu--window
- ;; There are 6 menus items in the main view
- ;; beep to beep
- ;; zoom simulates clicking on the window zoom box
- ;; disabled a disabled menu item that does nothing, in bold
- ;; close simulates a click on the close box
- ;; check a menu-item with the checkmark character
- ;; - an empty item
-
- ;; The view contains a subview of class marking-text-view, a marking menu view
-
- (defclass nested-window (marking-menu-window)
- ()
- (:default-initargs :window-title "Nested marking-views"
- :menu-diameter 185
- :menu-floating *floating*
- :menu-opaque *opaque*
- :menu-font default-font
- :auto-size t))
-
-
- ;; Marking menu functions associated with a nested-window
- (defmethod zoom-it ((self window))
- ;; similates clicking on the zoom-box for the window
- (window-zoom-event-handler self
- (if (equal (view-size self) (window-default-zoom-size self))
- 7
- 8)))
-
-
- ;; Text associated with a subview of a nested window
- (defvar help-1
- (format nil
- "Press the mouse button down in the window.~
- Wait till the menu appears. ~
- To select an item release the button. ~
- To cancel, release in the center. ~
- Items that can be chosen are hilited. ~
- You'll leave a rubber band where you go.
-
- Page 1/2"))
-
- (defvar help-2
- (format nil
- "When you've practiced, don't wait, just make a mark and you'll leave an ink trail. ~
- You can make marks outside the window. ~
- Whenever you wait, the menu will pop up. ~
- The menu here is not the same as the one outside the box.
-
- Page 2/2"))
-
- ;; A marking-menu-view which is a subview of a nested window
- ;; the view contains a check-box-dialog-item and a static-text-dialog-item
- (defclass marking-text (marking-menu-view static-text-dialog-item)
- ;; a marking-menu-view which is also a text dialog item with a frame around it.
- ()
- (:default-initargs :view-position #@(10 10)
- :view-nick-name 'box
- :view-size #@(300 120)
- :menu-font default-font
- :view-font '("Times" 14 :srccopy :plain)
- :menu-floating *floating*
- :menu-opaque *opaque*
- :auto-size t))
-
- (defmethod view-draw-contents ((view marking-text))
- ;; specialized method for drawing a marking-text,
- ;; draws a frame around the view
- (call-next-method view)
- (with-focused-view view
- (rlet ((rect :rect :topLeft #@(0 0)
- :bottomRight (view-size view)))
- (#_framerect :ptr rect))))
-
- (defmethod initialize-instance :after ((view marking-text) &rest initargs)
- (declare (ignore initargs))
- (let (text-box check next previous check-box)
- (get-menu-options view)
-
- (setq text-box ; add an indented text box indented
- (make-instance 'static-text-dialog-item
- :view-size (subtract-points (view-size view) #@(10 10))
- :view-position #@(5 5)
- :view-nick-name 'help
- :view-font (view-font view)
- :dialog-item-text help-1)
-
- check-box ; and a check-box-dialog-item
- (make-instance 'check-box-dialog-item
- :view-font (view-font view)
- :view-size #@(70 15)
- :view-position #@(220 100)
- :view-nick-name 'check-box
- :dialog-item-text "Inner"))
-
- ;; create three menu items, one to demonstrate check marks, and two to
- ;; move forward/backwards through the help text
- (setq check (make-instance 'check-window-menu-item
- :menu-item-title "Check"
- :mark "√")
-
- next (make-instance 'window-menu-item
- :menu-item-title "Next")
-
- previous (make-instance 'window-menu-item
- :menu-item-title "Prev"
- :disabled t))
-
- (setf (dialog-item-action-function check-box)
- #'(lambda (item)
- (let ((container (view-container item)))
- (set-menu-item-check-mark (find-menu-item container "Check")
- (check-box-checked-p item))))
-
- (menu-item-action-function check)
- #'(lambda (item)
- (let* ((container (containing-view item))
- (check-bx (view-named 'check-box container))
- (checked (check-box-checked-p check-bx)))
- (eval-enqueue `(check-another ,check-bx (not ,checked)))))
-
- (menu-item-action-function previous)
- #'(lambda (item)
- (let* ((container (containing-view item))
- (nxt (find-menu-item container "Next")))
- (set-dialog-item-text (view-named 'help container) help-1)
- (menu-item-disable item)
- (menu-item-enable nxt)))
-
- (menu-item-action-function next)
- #'(lambda (item)
- (let* ((container (containing-view item))
- (prev (find-menu-item container "Prev")))
- (set-dialog-item-text (view-named 'help container) help-2)
- (menu-item-disable item)
- (menu-item-enable prev))))
-
- (add-subviews view text-box check-box)
- (add-menu-items view check next previous)))
-
- (defmethod initialize-instance :after ((view nested-window) &rest initargs)
- (declare (ignore initargs))
- (let (beep zoom disabled close check null-item check-box)
- (declare (ignore initargs))
- (get-menu-options view)
- (add-subviews view (make-instance 'marking-text))
- ;; add a menu with 6 menu-items to the view
- ;; beep to beep
- ;; zoom click on window the zoom box
- ;; disabled for a disabled menu item that does nothing, in bold
- ;; close click on the close box
- ;; check a menu-item with the checkmark character
- ;; - an empty item
- (setq check-box (make-instance 'check-box-dialog-item
- :view-font (view-font view)
- :view-nick-name 'checker
- :view-size #@(70 15)
- :view-position #@(400 20)
- :dialog-item-text "Outer")
-
- beep (make-instance 'menu-item
- :menu-item-title "Beep"
- :menu-item-action #'(lambda ()
- (#_sysBeep :integer 1)))
-
- zoom (make-instance 'window-menu-item
- :menu-item-title "Zoom"
- :style :italic
- :menu-item-action
- #'(lambda (item)
- (zoom-it (containing-view item))))
-
- disabled (make-instance 'menu-item
- :menu-item-title "Disabled"
- :disabled t
- :style :bold)
-
- close (make-instance 'window-menu-item
- :menu-item-title "Close"
- :menu-item-action #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue
- `(window-close ,container)))))
-
- check (make-instance 'check-window-menu-item
- :menu-item-title "Check"
- :mark "√")
-
- null-item (make-instance 'empty-menu-item))
-
- (setf (dialog-item-action-function check-box)
- #'(lambda (item)
- (let ((container (view-container item)))
- (set-menu-item-check-mark (find-menu-item container "Check")
- (check-box-checked-p item))))
-
- (menu-item-action-function check)
- #'(lambda (item)
- (let* ((container (containing-view item))
- (check-bx (view-named 'checker container))
- (checked (check-box-checked-p check-bx)))
- (eval-enqueue `(check-another ,check-bx (not ,checked))))))
-
- (add-subviews view check-box)
- (add-menu-items view beep zoom disabled close check null-item)))
-
- (defmethod check-another ((dialog-item check-box-dialog-item) flag)
- (if flag
- (check-box-check dialog-item)
- (check-box-uncheck dialog-item)))
-
- ;; Define a class of marking-menu-table, a sequence dialog item
- ;; with three menu items
- ;; Next to skip forward through the list of numbers (0 - 10)
- ;; Prev to skip backward through the list of numbers (0 - 10)
- ;; Examine to print an English representation of the number in the list
- ;;
- ;; The double-click-action is equivalent to Examine.
-
- (defclass menu-table (marking-menu-table)
- ()
- (:default-initargs
- :table-dimensions 11
- :view-position #@(50 50)
- :view-size #@(112 31)
- :CELL-SIZE #@(28 16)
- :TABLE-HSCROLLP T
- :TABLE-VSCROLLP NIL
- :sequence-order :horizontal
- :view-position #@(10 50)
- :on-axis nil
- :view-size #@(123 46)
- :menu-diameter 165
- :menu-font default-font
- :menu-floating *floating*
- :menu-opaque *opaque*
- :auto-size t))
-
- (defmethod scroll-forward ((self table-dialog-item))
- (let* ((first-cell (point-h (scroll-position self)))
- (ncells (point-h (table-dimensions self)))
- (visible-dimensions (point-h (visible-dimensions self)))
- (last-cell (min (1- (+ first-cell visible-dimensions))
- (- ncells visible-dimensions))))
- (when (< last-cell ncells)
- (scroll-to-cell self last-cell)
- (< (+ last-cell visible-dimensions) ncells))))
-
- (defmethod scroll-backward ((self table-dialog-item))
- (let* ((first-cell (point-h (scroll-position self)))
- (visible-dimensions (point-h (visible-dimensions self)))
- new-cell)
- (setq new-cell (max 0 (1+ (- first-cell visible-dimensions))))
- (scroll-to-cell self new-cell)
- (not (zerop new-cell))))
-
- (defmethod initialize-instance :after ((marking-menu-table menu-table) &rest initargs)
- (declare (ignore initargs))
- (let (forward backward (self marking-menu-table) close)
- (get-menu-options marking-menu-table)
- (set-table-sequence self '(0 1 2 3 4 5 6 7 8 9 10))
- ;; create two menu items to
- ;; move forward and backwards
- (setq forward (make-instance 'window-menu-item
- :menu-item-title "Next")
- close (make-instance 'window-menu-item
- :menu-item-title "Close"
- :menu-item-action #'(lambda (item)
- (let* ((container (containing-view item))
- (window (view-window container)))
- (eval-enqueue
- `(window-close ,window)))))
-
- backward (make-instance 'window-menu-item
- :disabled t
- :menu-item-title "Prev"))
-
- (add-menu-items self forward close backward)
-
- (setf (menu-item-action-function forward)
- #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue
- `(progn
- (unless (scroll-forward ,container)
- (menu-item-disable (find-menu-item ,container "Next")))
- (menu-item-enable (find-menu-item ,container "Prev"))))))
-
- (menu-item-action-function backward)
- #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue
- `(progn
- (unless (scroll-backward ,container)
- (menu-item-disable (find-menu-item ,container "Prev")))
- (menu-item-enable (find-menu-item ,container "Next")))))))))
-
- ;; create a window which contains a menu-table
- (defclass table-window (window)
- ()
- (:default-initargs
- :Window-title "Table dialog demo"
- :window-type :document-with-grow
- :view-position #@(50 50)
- :view-size #@(300 100)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)))
-
- (defmethod initialize-instance :after ((self table-window) &rest initargs)
- (declare (ignore initargs))
- (let (new-table textb examine items)
- (setq new-table (make-instance 'menu-table)
-
- examine (make-instance 'window-menu-item
- :menu-item-title "Examine")
-
- textb (make-instance 'static-text-dialog-item
- :view-size #@(80 30)
- :view-position #@(50 10)
- :view-nick-name 'text
- :view-font '("Times" 24 :srcor :plain)
- :dialog-item-text "Nothing"))
-
- (add-subviews self new-table textb)
- (setq items (menu-items new-table))
- (mapcar #'(lambda (item) (remove-menu-items new-table item)) items)
- (push examine items)
- (mapcar #'(lambda (item) (add-menu-items new-table item)) items)
-
- (setf (menu-item-action-function examine)
- #'(lambda (item)
- (let ((table (containing-view item))
- (text (find-named-sibling new-table 'text)))
- (set-dialog-item-text
- text
- (format nil "~r" (cell-contents new-table
- (first (selected-cells table)))))))
-
- (slot-value new-table 'menus::menu-double-click-action-function)
- #'(lambda (item)
- (let ((table (containing-view item))
- (text (find-named-sibling new-table 'text)))
- (set-dialog-item-text
- text
- (format nil "~r" (cell-contents table
- (first (selected-cells table))))))))))
-
- (defun nested-demo ()
- (queued-modal-dialog (make-instance 'nested-window)))
-
- (defun table-demo ()
- (queued-modal-dialog (make-instance 'table-window)))
-
- ;; Create a dialog window with a menu with 6 items:
- ;; Nested to demonstrate nested marking menus (class nested-window)
- ;; Table to demonstrate marking-menu-table
- ;; - an empty emnu item
- ;; Floating a check-menu-item: use floating menus when checked
- ;; Opaque a check-menu-item: use opaque menus when checked
- ;; and when floating is also checked
- ;; Quit to end the demonstration
- (defclass marking-dialog (marking-menu-window)
- ()
- (:default-initargs
- :window-type :shadow-edge-box
- :view-position :centered
- :view-size #@(311 169)
- :on-axis nil
- :close-box-p nil
- :view-font '("Chicago" 12 :srcor :plain)
- :menu-font default-font
- :menu-diameter 210
- :menu-floating *floating*
- :menu-opaque *opaque*
- :auto-size t))
-
- (defmethod initialize-instance :after ((view marking-dialog) &rest init-args)
- (declare (ignore init-args))
- (let ((floating (make-instance 'check-menu-item
- :menu-item-title "Floating"
- :mark "√"))
- (opaque (make-instance 'check-menu-item
- :menu-item-title "Opaque"
- :mark "√")))
- (get-menu-options view)
- (setf (menu-item-action-function floating)
- #'(lambda ()
- (let ((checked
- (menu-item-check-mark floating)))
- (setq *floating* checked)
- (if checked
- (menu-item-enable opaque)
- (progn (menu-item-disable opaque)
- (set-menu-item-check-mark opaque nil)
- (setf (slot-value view 'menus::menu-opaque)
- nil)
- (setq *opaque* nil)))
- (eval-enqueue `(setf (slot-value ,view 'menus::menu-floating)
- ,checked))))
- (menu-item-action-function opaque)
- #'(lambda ()
- (let ((checked
- (menu-item-check-mark opaque)))
- (setq *opaque* checked)
- (setf (slot-value view 'menus::menu-opaque)
- checked))))
- (set-menu-item-check-mark floating *floating*)
- (set-menu-item-check-mark opaque *opaque*)
- (unless *floating*
- (menu-item-disable opaque))
- (add-subviews view
- (make-instance 'static-text-dialog-item
- :view-position #@(49 34)
- :view-size #@(223 60)
- :dialog-item-text "Hold the mouse button down to try marking menus. Experiment with the options."
- :view-font '("Chicago" 12 :srccopy :plain)))
- (add-menu-items view
- (make-instance 'window-menu-item
- :menu-item-title "Nested"
- :menu-item-action #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue
- `(progn
- (window-hide ,container)
- (nested-demo)
- (window-select ,container))))))
- (make-instance 'window-menu-item
- :menu-item-title "Table"
- :menu-item-action #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue
- `(progn
- (window-hide ,container)
- (table-demo)
- (window-select ,container))))))
- floating
- opaque
- (make-instance 'window-menu-item
- :menu-item-title "Quit"
- :menu-item-action #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue `(window-close ,container)))))
-
- (if *custom*
- (make-instance 'window-menu-item
- :menu-item-title "Graphic"
- :menu-item-action #'(lambda (item)
- (let ((container (containing-view item)))
- (eval-enqueue
- `(progn
- (window-hide ,container)
- (queued-modal-dialog (make-instance 'gdemo-window :window-show t))
- (window-select ,container))))))
- (make-instance 'empty-menu-item))
- )))
-
- (defun marking-demo ()
- (queued-modal-dialog (make-instance 'marking-dialog)))
-
- (defun make-marking-demo ()
- "Create the experiment application"
- (let ((target-appl (choose-new-file-dialog :directory "ccl;marking-menus")))
- (setq *testing* nil)
- (set-menubar nil)
- (save-application target-appl
- :excise-compiler t ; don't want the compiler
- :clear-clos-caches nil ; otherwise we can't access classes
- :toplevel-function #'marking-demo)))
-
- #|
- ; (make-marking-demo) to create an application
- |#
-
-